/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;

/**
 *
 * @author Matthy & Jelle
 */
@Entity
@Table(name="T_VERKOOP")
public class Verkoop implements Cloneable{
  @Id @GeneratedValue(strategy= GenerationType.IDENTITY)
  private Integer id;
  @ManyToOne(optional=false, cascade=javax.persistence.CascadeType.PERSIST)
  @JoinColumn(name="verkooppunt_id")
  private VerkoopPunt verkooppunt;
  @ManyToOne
  @JoinColumn(name="klant_id")
  private Klant klant;
  @Temporal(javax.persistence.TemporalType.DATE)
  private Date datum;
  @OneToMany(mappedBy="verkoop")
  private List<Ticket> tickets;

  public Verkoop() {
    this.tickets = new ArrayList<Ticket>();
  }

  public void setId(Integer Id) {
    this.id = Id;
  }

  public void setVerkooppunt(VerkoopPunt verkooppunt) {
    this.verkooppunt = verkooppunt;
  }

  public void setKlant(Klant klant) {
    this.klant = klant;
  }

  public void setDatum(Date datum) {
    this.datum = datum;
  }

  public void setTickets(List<Ticket> tickets) {
    this.tickets = tickets;
    for (Ticket t : tickets) {
      t.setVerkoop(this);
    }
  }

  public Integer getId() {
    return id;
  }

  public VerkoopPunt getVerkooppunt() {
    return verkooppunt;
  }

  public Klant getKlant() {
    return klant;
  }

  public Date getDatum() {
    return datum;
  }

  public List<Ticket> getTickets() {
    return tickets;
  }

  @Override
  public Object clone() {
    try {
      Verkoop clone = (Verkoop)super.clone();
      clone.setTickets(new ArrayList<Ticket>());
      return clone;
    } catch (CloneNotSupportedException ex) {
      return null;
    }
  }


}
